import 'package:flutter/material.dart';
import 'package:wallpaper/model/options_base.dart';
import 'package:wallpaper/pages/navbar/child/mohu_imgs.dart';
import 'package:wallpaper/tools/route_animation.dart';

class MohuList extends StatefulWidget {
  final List<dynamic> types;
  const MohuList({super.key, required this.types});

  @override
  State<MohuList> createState() => _MohuListState();
}

class _MohuListState extends State<MohuList>
    with AutomaticKeepAliveClientMixin {
  @override
  Widget build(BuildContext context) {
    super.build(context); // 必须调用 super.build
    return Scaffold(
      body: Container(
        padding: EdgeInsets.all(OptionsBase().padding),
        child: GridView.builder(
            itemCount: widget.types.length,
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: OptionsBase().imageColumns(context),
              crossAxisSpacing: OptionsBase().padding,
              mainAxisSpacing: OptionsBase().padding,
              childAspectRatio: 4,
            ),
            itemBuilder: (context, index) {
              return ElevatedButton(
                style: ButtonStyle(
                  backgroundColor: WidgetStateProperty.all(
                      Theme.of(context).colorScheme.primaryContainer),
                  shape: WidgetStateProperty.all(RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(5),
                  )),
                ),
                child: Text(
                  widget.types[index]['label'],
                  style: TextStyle(
                    color: Theme.of(context).colorScheme.inversePrimary,
                  ),
                  overflow: TextOverflow.ellipsis,
                ),
                onPressed: () {
                  RouteAnimation().animateRoute(
                      context,
                      MohuImgs(
                        type: widget.types[index]['value'],
                        title: widget.types[index]['label'],
                      ));
                },
              );
            }),
      ),
    );
  }

  @override
  bool get wantKeepAlive => true;
}
